//! \file iopoll.hpp
//! \brief Purewell Library IO Poll Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2008-01-25

#ifndef __PWHDR_IOPOLL_HPP__
#define __PWHDR_IOPOLL_HPP__

namespace purewell
{

class PWFile;
class PWPairFile;

//! \brief IO Poll
class PWIOPoll
{
public:
	//! \brief Create I/O Poll
	//! \param[in] type Poll type.
	//! \return On success, Poll pointer.
	static PWIOPoll* create(const char* type);

	//! \brief Release I/O Poll
	//! \param[in,out] io Poll.
	static void release(PWIOPoll* io);

public:
	inline virtual ~PWIOPoll() {}

	//! \brief Add file event to poll.
	//! \param[in] pfile File to poll.
	//! \param[in] event Event.
	//! \return On success, true.
	virtual bool add(PWFile* pfile, int event) = 0;

	//! \brief Add file event to poll.
	//! \param[in] pfile File to poll.
	//! \param[in] idx Index of file descriptor.
	//! \param[in] event Event.
	//! \return On success, true.
	virtual bool add(PWPairFile* pfile, size_t idx, int event) = 0;

	//! \brief Modify file event to poll.
	//! \param[in] pfile File to poll.
	//! \param[in] event Event.
	//! \return On success, true.
	virtual bool modify(PWFile* pfile, int event) = 0;

	//! \brief Modify file event to poll.
	//! \param[in] pfile File to poll.
	//! \param[in] idx Index of file descriptor.
	//! \param[in] event Event.
	//! \return On success, true.
	virtual bool modify(PWPairFile* pfile, size_t idx, int event) = 0;

	//! \brief Modify file event to poll.
	//! \param[in] fd File descriptor.
	//! \param[in] event Event.
	//! \return On success, true.
	virtual bool modify(int fd, int event) = 0;

	//! \brief Remove file event from poll.
	//! \param[in] pfile File from poll.
	//! \return On success, true.
	virtual bool remove(PWFile* pfile) = 0;

	//! \brief Remove file event from poll.
	//! \param[in] pfile File to remove.
	//! \param[in] idx Index of file descriptor.
	//! \return On success, true.
	virtual bool remove(PWPairFile* pfile, size_t idx) = 0;

	//! \brief Remove file descriptor from poll.
	//! \param[in] fd File descriptor.
	//! \return On success, true.
	virtual bool remove(int fd) = 0;

	//! \brief Dispatch event.
	//! \param[in] msec Time to wait. Unit is millisecond.
	//! \return On success, true.
	virtual bool dispatch(int msec) = 0;

	//! \brief Get type.
	//! \return Type string.
	virtual const char* getType(void) const = 0;

	//! \brief Initialize poll.
	//! \param[in] param Parameter.
	//! \return On success, true.
	virtual bool initialize(void* param = NULL) = 0;

	//! \brief Destroy poll.
	virtual void destroy(void) = 0;
};

};// namespace purewell

#endif//!__PWHDR_IOPOLL_HPP__

